const uuidv1 = require('uuid')
const moment = require('moment')


function isNotNullAndSpace(s) {
    if (s == undefined) {
        return false
    }

    if(s == "") {
        return false
    }
    return true
}

function isNullOrSpace(s) {
    if (s == undefined) {
        return true
    }

    if(s == "") {
        return true
    }
    return false
}

function getUUID() {
    const s = uuidv1.v1()
    return s.replace(/-/g, '')
}

function queryRandomNo() {
    let num = Math.floor(Math.random() * 10000)
    num = num.toString()
    return num
}

function intToFen(x) {
    return (x / 100).toFixed(2)
}


function addMysqlPageSize(sql, pageIndex, pageSize) {
    pageIndex = pageIndex || 0
    pageSize = pageSize || 10
    pageIndex = parseInt(pageIndex)
    if (pageIndex > 0) {
        pageIndex -= 1
    }
    pageSize = parseInt(pageSize)
    return sql + ` limit ` + pageIndex * pageSize + ', ' + pageSize  
}

function getDateYYYYMMDD() {
    return moment().format('YYYYMMDD')
}

function format(num, size) {
    num = num.toString()
    return num.padStart(size, '0')
}

module.exports = {
    format,
    isNotNullAndSpace,
    isNullOrSpace,
    getUUID,
    queryRandomNo,
    intToFen,
    addMysqlPageSize,
    getDateYYYYMMDD,
}